/**
 * 
 */
package com.swim.platform.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.swim.platform.entity.PlatformReservation;
import com.swim.platform.service.PlatformReservationService;

/**
 * 平台预约Controller
 * @author ljw
 * @version 2023-04-23
 */
@Controller
@RequestMapping(value = "${adminPath}/platform/platformReservation")
public class PlatformReservationController extends BaseController {

	@Autowired
	private PlatformReservationService platformReservationService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public PlatformReservation get(String id, boolean isNewRecord) {
		return platformReservationService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("platform:platformReservation:view")
	@RequestMapping(value = {"list", ""})
	public String list(PlatformReservation platformReservation, Model model) {
		model.addAttribute("platformReservation", platformReservation);
		return "swim/platform/platformReservationList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("platform:platformReservation:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<PlatformReservation> listData(PlatformReservation platformReservation, HttpServletRequest request, HttpServletResponse response) {
		Page<PlatformReservation> page = platformReservationService.findPage(new Page<PlatformReservation>(request, response), platformReservation); 
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("platform:platformReservation:view")
	@RequestMapping(value = "form")
	public String form(PlatformReservation platformReservation, Model model) {
		model.addAttribute("platformReservation", platformReservation);
		return "swim/platform/platformReservationForm";
	}

	/**
	 * 保存平台预约
	 */
	@RequiresPermissions("platform:platformReservation:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated PlatformReservation platformReservation) {
		platformReservationService.save(platformReservation);
		return renderResult(Global.TRUE, text("保存平台预约成功！"));
	}
	
}